﻿
<!Doctype html>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
  <title>好货分享</title>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
  <meta name="apple-touch-fullscreen" content="yes" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  <meta name="format-detection" content="telephone=no" />
  <script>
    !function () {
      var cw = document.documentElement.clientWidth || document.body.clientWidth, zoom = cw / 320;
      if (cw > 640) zoom = 2;
      document.write('<style id="htmlzoom">html{ font-size:' + (zoom * 50) + 'px; }</style>');
      window.addEventListener('resize', function () {
        cw = document.documentElement.clientWidth || document.body.clientWidth, zoom = cw / 320;
        if (cw > 640) zoom = 2;
        document.getElementById('htmlzoom').innerHTML = 'html{ font-size:' + (zoom * 50) + 'px; }';
      });
    }();
  </script>
  <script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/layer-mobile@2.0.1/dist/layer.min.js"></script>
  <style type="text/css">
    body, p, form, h1, h2, h3, h4, h5, h6, ul, ol, li, section, div, * { padding: 0; margin: 0; }
    body { background-color: #f3f3f3; min-width: 300px; max-width: 640px; margin: 0 auto; font-size: .24rem; font-family: arial, "\5FAE\8F6F\96C5\9ED1"; }
    .photo { padding-bottom: .8rem; }
    .photo img { width: 100%; vertical-align: middle; }
    .coupon em { display: block; padding: .16rem 0; background-color: #ea3b4c; color: #fff; font-style: normal; text-align: center; }
    .coupon .copy-box { width: 100%; font-size: .24rem; padding: .4rem 0 .28rem; text-align: center; border: dashed 1px #ea3b4c; background-color: #fff; -webkit-user-select: text; box-sizing: border-box; }
    .copy { width: 100%; border: none 0; background-color: #ff692f; color: #fff; padding: .2rem 0; font-size: .26rem; vertical-align: middle; outline: 0; border-radius: 0; text-align: center; cursor: pointer; }
    .copy.success { background-color: #19d125; }
    .copy.fail { background-color: #ccc; }

    .special { position: fixed; bottom: 0; width: 100%; max-width: 640px; height: .8rem; background: #fe0037 url(12.png) no-repeat .14rem center; background-size: 2.4rem; text-align: right; }
    .special p { padding-right: .14rem; color: #fff; font-size: .4rem; line-height: .8rem; }
    .special .hongbao { position: absolute; left: 50%; bottom: -.1rem; margin-left: -.6rem; }
    .special .hongbao img { width: 1.2rem; -webkit-animation: "scaleAnim" .5s infinite; }

    @-webkit-keyframes
    'scaleAnim' { 0%
    { -webkit-transform: scale(.9); transform: scale(.9); -moz-transform: scale(.9); -o-transform: scale(.9); }
    50% { -webkit-transform: scale(1.1); transform: scale(1.1); -moz-transform: scale(1.1); -o-transform: scale(1.1); }
    100% { -webkit-transform: scale(.9); transform: scale(.9); -moz-transform: scale(.9); -o-transform: scale(.9); }
    }
  </style>
</head>
<body>
  <iframe id="iframe" style="display:none"></iframe>
  <section id="content">
    <div class="coupon">
      <em>长按框内 &gt; 全选 &gt; <span id="tip">复制</span> &gt; 打开淘宝APP</em>
      <div class="copy-box">复制本信息→打开淘宝APP即可购买</div>
      <div class="copy">一键复制</div>
    </div>
    <div class="photo"></div>
  </section>
  <div class="special" data-clipboard-text="￥zpfdbOluMRk￥">
    <p>开抢超级红包</p>
    <div class="hongbao"><img src="hb.png" /></div>
  </div>
  <script type="text/javascript">
    //UA
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/iphone/i) == "iphone" || ua.match(/ipad/i) == "ipad") {
      document.getElementById('tip').innerText = "拷贝";
    }

    //自动选中
    var key = document.querySelector('.copy-box');
    document.addEventListener("selectionchange",
      function (e) {
        window.getSelection().selectAllChildren(key);
      },
      false);

    //获得参数
    function getQueryVariable(variable) {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) { return unescape(pair[1]); }
      }
      return (false);
    }
    var token = "￥" + getQueryVariable("k").match(/\w+/) + "￥";
    document.querySelector(".copy").setAttribute('data-clipboard-text', token);
    key.innerText += token;

    var img = document.getElementById('iframe').contentWindow.document.createElement('img');
    var picurl = getQueryVariable("image").replace("(a)", "https://gchat.qpic.cn/gchatpic_new/").replace("(b)", "https://img.alicdn.com/imgextra/");
    img.src = picurl;
    img.onload = function () { document.querySelector(".photo").appendChild(img) };

    var clipboard = new ClipboardJS(".copy");
    clipboard.on('success', function (e) { if (!e.trigger.className.match(/success/)) { e.trigger.className += " success"; } e.trigger.innerText = "复制成功，请打开淘宝APP"; });
    clipboard.on('error', function (e) { if (!e.trigger.className.match(/fail/)) { e.trigger.className += " fail"; } e.trigger.innerText = "复制失败，请长按框内手工复制"; });

    var hb_clipboard = new ClipboardJS(".special");
    hb_clipboard.on('success', function (e) {
      layer.open({
        content: '红包淘口令已成功，请打开淘宝APP'
        , skin: 'msg'
        , time: 2 //2秒后自动关闭
      });
    });
    hb_clipboard.on('error', function (e) {
      layer.open({
        content: '红包淘口令复制失败，请重试'
        , skin: 'msg'
        , time: 2 //2秒后自动关闭
      });
    });
  </script>
</body>
</html>